
from django.views import View

from User.models import OrderVip, OrderGoods
from Venue.models import Vip, Goods
from sportsground.utils import Req
from sportsground.utils.Res import Res
from sportsground.utils.views import LoginRequiredVenue


class VerifyGoodsView(LoginRequiredVenue, View):
    """ 商品验证 """

    @Req.getJson
    def post(self, request):
        """ 添加 """
        orderGoodsId = request.json_dict.get('orderGoodsId')
        verify = request.json_dict.get('verify','')

        venue = request.user.venue

        orderGoods = OrderGoods.objects.filter(id=orderGoodsId).first()
        if not orderGoodsId:
            return Res.Json(Res.ParamErr)

        if orderGoods.getTime:
            return Res.Json(Res.Warn, msg="已校验")
        if not orderGoods.verifyCode(verify):
            return Res.Json(Res.Warn, msg="校验码错误")

        return Res.Json(Res.OK)
